<template>
	<view class="content">
		<!-- 背景渐变 -->
		<view class="gradient-bg"></view>
		<!-- 四列数据展示 -->
		<view class="data-columns">
			<view class="column" v-for="(item, index) in columnsData" :key="index">
				<p>{{ item.description }}</p>
				<p class="total">{{ item.total||0 }}</p>
			</view>
		</view>
		<!-- 内容盒子 -->
		<view class="content-box">
			<view class="" style="display: flex;padding: 20rpx;">
				<view class="team-details">
					<text>团队明细</text>
				</view>
				<view class="buttons">
					<view class="button" v-for="(btn, idx) in buttons" :key="idx"
						:class="{ 'active': selectedButton === btn }" @click="selectButton(btn)">
						{{ btn }}
					</view>
				</view>
			</view>
			<!-- 搜索框 -->
			<!-- <uni-search-bar class="uni-mt-10" radius="5" placeholder="自动显示隐藏" clearButton="auto" cancelButton="none"
				@input="searchInput" /> -->
			<!-- 排序按钮 -->
			<!-- <view class="sort-buttons">
				<view class="sort-button" @click="toggleSort('team')">
					团队排序 <text class="arrow">{{ teamSortOrder ? '↑' : '↓' }}</text>
				</view>
				<view class="sort-button" @click="toggleSort('amount')">
					金额排序 <text class="arrow">{{ amountSortOrder ? '↑' : '↓' }}</text>
				</view>
				<view class="sort-button" @click="toggleSort('general')">
					排序 <text class="arrow">{{ generalSortOrder ? '↑' : '↓' }}</text>
				</view>
			</view> -->
			<!-- 内容列表 -->
			<view class="list-item" v-for="(item, index) in contentList" :key="index">
				<image :src="item.userInfo.headPortrait" class="avatar"></image>
				<view class="item-details">
					<p class="name">{{ item.userInfo.nickName }}</p>
					<p class="time" style="color: #666;">{{ item.lastModificationTime }}</p>
				</view>
				<view class="item-content">
					<view class="item-data">
						<p class="label">推广人数</p>
						<p class="value">{{ item.numberOfInvitations || 0 }}</p>
					</view>
					<view class="item-data">
						<p class="label">成交金额</p>
						<p class="value">{{ item.tradingVolume || 0 }}</p>
					</view>
					<view class="item-data">
						<p class="label">成交单量</p>
						<p class="value">{{ item.orderVolume || 0 }}</p>
					</view>
				</view>
			</view>
		</view>
		<view v-if="!contentList.length">
			<image style="margin:10%;" src='../../../static/null/null.png'></image>
		</view>
	</view>
</template>

<script>
	import {
		getTeamLevel,
		getUserInfo
	} from '@/api/user.js';
	export default {
		data() {
			return {
				selectedButton: '一级',
				buttons: ['一级', '二级'],
				columnsData: [{
						total: '',
						description: '总人数'
					},
					// {
					// 	total: '100',
					// 	description: '今日新增'
					// },
					// {
					// 	total: '100',
					// 	description: '昨日新增'
					// },
					// {
					// 	total: '500',
					// 	description: '本月新增'
					// },
				],
				teamSortOrder: false,
				amountSortOrder: false,
				generalSortOrder: false,
				userInfo: {},
				contentList: [],
				pageNumber: 1,
				pageSize: 10,
			};
		},
		onLoad() {
			this.getUser()
			this.getTeam()
		},
		methods: {
			//获取用户信息
			getUser() {
				getUserInfo().then(res => {
					this.userInfo = res.data
					this.columnsData[0].total = res.data.promotionNumber
					console.log(res.data.promotionNumber,"res.data.promotionNumber")
				});
			},
			getTeam() {
				const params = {
					pageSize: this.pageSize,
					pageNumber: this.pageNumber,
					level: this.selectedButton === '一级' ? 1 : 2,
				};
				getTeamLevel(params).then(res => {
					if (this.pageNumber === 1) {
						this.contentList = res.data.records;
					} else {
						this.contentList = [...this.contentList, ...res.data.records];
					}
					console.log(this.contentList, "contentList")
				});
			},
			selectButton(button) {
				this.selectedButton = button;
				this.pageNumber = 1; // 重置分页
				this.getTeam();
			},
			onReachBottom() {
				this.pageNumber++;
				this.getTeam();
			},
		}
	};
</script>

<style lang="scss">
	@import '@/uni.scss'; // 导入全局 SCSS 变量文件

	.content {
		position: relative;
		min-height: 100vh;
		background-color: #F3F3F3;
		padding: 20rpx;
		background: linear-gradient(to bottom, #FF5B13, #F3F3F3);
		background-size: 100% 400rpx;
		background-repeat: no-repeat;

		.gradient-bg {
			width: 100%;
			position: absolute;
			z-index: 1;
		}

		.data-columns {
			display: flex;
			z-index: 2;
			font-size: 26rpx;
			margin-top: 80rpx;

			.column {
				flex: 1 0 20%;
				text-align: center;
				color: #ffffff;

				&:first-child {
					flex: 1 0 30%;
					text-align: left;
					margin-top: -32rpx;

					.total {
						font-size: 60rpx;
						font-weight: bold;
					}
				}

				.total {
					font-size: 32rpx;
					font-weight: bold;
				}
			}
		}

		.content-box {
			margin-top: 20rpx;
			display: flex;
			flex-direction: column;
			background-color: white;
			border-radius: 8rpx;
			box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
			overflow: hidden;

			.team-details {
				width: 70%;
			}

			.buttons {
				width: 200rpx;
				display: flex;
				background-color: gray;
				border-radius: 18rpx;

				.button {
					width: 100rpx;
					height: 48rpx;
					text-align: center;
					color: #fff;
					background-color: gray;
					transition: all 0.3s;
					border-radius: 18rpx;


					&.active {
						width: 100rpx;
						height: 48rpx;
						background-color: #FF5B13;
						color: #ffffff;
						border-radius: 18rpx;

					}
				}
			}

			.sort-buttons {
				display: flex;
				justify-content: space-around;
				background-color: #f9f9f9;
				padding: 20rpx;
				font-size: 28rpx;

				.arrow {
					font-size: 28rpx;
				}
			}


			.list-item {
				width: 100%;
				display: flex;
				flex-wrap: wrap;
				align-items: center;
				padding: 20rpx;
				border-bottom: 1rpx solid #ddd;

				&:last-child {
					border: none;
				}

				.avatar {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					margin-right: 20rpx;
				}

				.item-details {
					width: 80%;

					.name {
						font-weight: bold;
					}
				}

				.item-content {
					width: 94%;
					display: flex;
					justify-content: center;
					flex-wrap: nowrap;
					text-align: center;
					background-color: #ececec;
					padding: 20rpx 0rpx;
					margin: 20rpx 0rpx;

					.item-data {
						width: 33%;

						.label {
							color: #989898;
						}

						.value {
							font-weight: bold;
						}
					}
				}

			}
		}
	}
</style>